<?php
    class BoatHandler {
    	private $m_dbConnection = null;
		
		// Tables:
		private $m_memberTableName = "member";
		private $m_boatTableName = "boatRegister";
		
        public function __construct(DBConnection $a_connection) {
                $this->m_dbConnection = $a_connection;
        }

		
		
		public function AddBoatInfo($m_memberId, $m_type, $m_length) {
			$sql = "INSERT INTO $this->m_boatTableName (m_boatId, m_type, m_length, m_memberId) VALUES(NULL, ?, ?, ?)";
			$stmt = $this->m_dbConnection->Prepare($sql);
			$stmt->bind_param("sii", $m_type, $m_length, $m_memberId);		
			if($stmt->execute()) {
				$stmt->close();
				return true;
			} else {
				$stmt->close();
				return false;
			}
		}
		
		public function ChangeBoatInfo($m_boatId, $m_type, $m_length) {
			$sql = "UPDATE $this->m_boatTableName SET m_type=?, m_length=? WHERE m_boatId=?";
			$stmt = $this->m_dbConnection->Prepare($sql);
			$stmt->bind_param("ssi", $m_type, $m_length, $m_boatId);
			
			if($stmt->execute()) {
				$stmt->close();
				return true;
			} else {
				$stmt->close();
				return false;
			}
		}
		
		public function DeleteBoatInfo($m_boatId) {
			$sql = "DELETE FROM $this->m_boatTableName WHERE m_boatId=?";
			$stmt = $this->m_dbConnection->Prepare($sql);

			$stmt->bind_param("i", $m_boatId);
			
			if($stmt->execute()) {
				$stmt->close();
				return true;
			} else {
				$stmt->close();
				return false;
			}
		}
    }
?>